﻿using System.Web.Mvc;
using System.Web.Routing;
using Blog.Infrastructure.Configuration.Blog.Infrastructure.Config;
using Blog.Presentation.Handlers;
using Blog.Presentation.StructureMap;

namespace Blog.Presentation
{
    
    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("Feeds.ashx/{*pathInfo}");
            routes.IgnoreRoute("elmah.axd");

            routes.Add(new Route("{weblog}", null,
                new RouteValueDictionary(new { weblog = "blogapi" }),
                new MetaWeblogRouteHandler()));

            routes.MapRoute("WlwManifest",
                "wlwmanifest.xml",
                new { controller = "LiveWritter", action = "Manifest" });

            routes.MapRoute("Rsd",
               "rsd.xml",
               new { controller = "LiveWritter", action = "Rsd" });

            routes.MapRoute("Sitemap",
                "Sitemap.xml",
                new { controller = "Home", action = "Sitemap" });

            routes.MapRoute(
                 "Page",
                 "Archive/Page/{index}",
                 new { controller = "Articles", action = "Archive" }
             );

            routes.MapRoute(
                "MyWorld",
                "Archive/MyWorld/{index}",
                new { controller = "Articles", action = "MyWorld" }
            );
            routes.MapRoute(
                 "Category",
                 "{category}",
                 new { controller = "Articles", action = "CategoryView" }
             );

            routes.MapRoute(
                  "Show",
                  "Archive/{title}",
                  new { controller = "Articles", action = "View" }
              );
            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new {controller = "Home", action = "Index", id = UrlParameter.Optional} // Parameter defaults
                );
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            Bootstrapper.Init();
            ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());
            //NHibernateConfigurator.MsSqlCeSessionFactory();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
         
        }

      
        



    }
}